/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfazRegistrarCalificaciones.java
 *
 * Created on 26/10/2011, 04:26:19 AM
 */
package presentacion;

import Paneles.PanelGeneral;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import business.AreaBO;
import business.AsignaturaBO;
import javax.swing.SpinnerNumberModel;
import javax.swing.JOptionPane;
import business.LogroBO;
import business.CursoBo;
import javax.swing.table.DefaultTableModel;
import business.EstudianteBO;
import dominio.Estudiante;
import javax.swing.ImageIcon;
import javax.swing.table.TableModel;
import presentacion.models.DefaultTableModelImpl;
import business.EstudianteLogroBO;
import dominio.EstudianteLogro;

/**
 *
 * @author vanessa
 */
public class InterfazRegistrarCalificaciones extends javax.swing.JFrame {

    private AreaBO areaBo = new AreaBO();
    private AsignaturaBO asignaturaBo = new AsignaturaBO();
    private LogroBO logroBo = new LogroBO();
    private CursoBo cursoBo = new CursoBo();
    private EstudianteBO estudianteBo = new EstudianteBO();
    private EstudianteLogroBO estudianteLogroBo = new EstudianteLogroBO();
    private final ImageIcon icono;

    /** Creates new form InterfazRegistrarCalificaciones */
    public InterfazRegistrarCalificaciones() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        icono = new ImageIcon(getClass().getResource("/Imagenes/icon.gif"));
        this.setIconImage(icono.getImage());
        cargarListaGrados();
        cargarListaAreas();
        cargarListaAsignaturas();
        cargarPeriodo();
        cargarComboPeriodo();
        cargarComboPeriodoConsulta();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        comboGrados = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        comboAreas = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        entradaLogro = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        periodoSpin = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        comboAsignaturas = new javax.swing.JComboBox();
        comboCursos = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCalificaciones = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaLogros = new javax.swing.JTable();
        botonRegistrarCalificaciones = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        comboPeriodo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        comboPeriodoConsulta = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        actualizarDescripción = new javax.swing.JButton();

        setTitle("Registrar Calificaciones");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jLabel1.setText("Buscar Asignatura:");

        jLabel3.setText("Grado");

        comboGrados.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboGrados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboGradosActionPerformed(evt);
            }
        });

        jLabel4.setText("Area");

        comboAreas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboAreas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboAreasActionPerformed(evt);
            }
        });

        jLabel7.setText("Digite el nuevo Logro:");

        jButton2.setText("Registrar Logro");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel8.setText("Periodo:");

        jLabel2.setText("Asignatura:");

        comboAsignaturas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboAsignaturas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboAsignaturasActionPerformed(evt);
            }
        });

        comboCursos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboCursosActionPerformed(evt);
            }
        });

        tablaCalificaciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Nombre del Estudiante"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaCalificaciones.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(tablaCalificaciones);
        tablaCalificaciones.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        jLabel6.setText("Ahora registre las calificaciones por curso:");

        tablaLogros.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Nro. del Logro", "Codigo del Logro", "Logro", "Periodo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaLogros.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane2.setViewportView(tablaLogros);
        tablaLogros.getColumnModel().getColumn(0).setPreferredWidth(100);
        tablaLogros.getColumnModel().getColumn(1).setPreferredWidth(100);
        tablaLogros.getColumnModel().getColumn(2).setPreferredWidth(700);

        botonRegistrarCalificaciones.setText("Registrar Calificaciones");
        botonRegistrarCalificaciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonRegistrarCalificacionesActionPerformed(evt);
            }
        });

        jButton3.setText("Consultar Calificaciones");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Salir");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel5.setText("Y por periodo:");

        comboPeriodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboPeriodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboPeriodoActionPerformed(evt);
            }
        });

        jLabel9.setText("Puede eliminar un logro seleccionado de la tabla");

        jButton5.setText("Eliminar Logro");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel10.setText("Consultar los Logros por periodo:");

        comboPeriodoConsulta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboPeriodoConsulta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboPeriodoConsultaActionPerformed(evt);
            }
        });

        jLabel11.setText("Tambien puede cambiar la descripción de los logros:");

        actualizarDescripción.setText("Cambiar Descripción");
        actualizarDescripción.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actualizarDescripciónActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(botonRegistrarCalificaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 987, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboAreas, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2)
                                .addGap(26, 26, 26)
                                .addComponent(comboAsignaturas, 0, 663, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addGap(18, 18, 18)
                                        .addComponent(periodoSpin, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(entradaLogro, javax.swing.GroupLayout.PREFERRED_SIZE, 754, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(120, 120, 120))))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 987, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(1, 1, 1)
                                .addComponent(comboCursos, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(comboPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addGap(18, 18, 18)
                                        .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel11)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(actualizarDescripción, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(comboPeriodoConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(9, 9, 9))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(comboGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(comboAreas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(comboAsignaturas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(entradaLogro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(periodoSpin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jButton5)
                    .addComponent(jLabel10)
                    .addComponent(comboPeriodoConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(actualizarDescripción)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(comboCursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(comboPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(botonRegistrarCalificaciones)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        InterfazConsultarCalificaciones interfazConsultarCalificaciones = new InterfazConsultarCalificaciones();
        interfazConsultarCalificaciones.setVisible(true);

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void cargarListaAreas() {
        List l = areaBo.consultarAreas();
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboAreas.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccionar");
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i));
        }
        comboAreas.setModel(modelo);
    }

    private void cargarListaAsignaturas() {
        List lista = asignaturaBo.consultarAsignaturasAreaGrado(comboAreas.getSelectedItem() + "", comboGrados.getSelectedIndex() - 1);
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboAsignaturas.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < lista.size(); i++) {
            modelo.addElement(lista.get(i));
        }
        comboAsignaturas.setModel(modelo);
    }

    private void cargarComboPeriodo() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboPeriodo.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("Primero");
        modelo.addElement("Segundo");
        modelo.addElement("Tercero");
        modelo.addElement("Cuarto");
    }

    private void cargarComboPeriodoConsulta() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboPeriodoConsulta.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("Primero");
        modelo.addElement("Segundo");
        modelo.addElement("Tercero");
        modelo.addElement("Cuarto");
    }

    private void cargarListaCursosGrado(Integer idGrado) {
        List lista = cursoBo.consultarCursosGrado(idGrado);
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboCursos.getModel();
        modelo.removeAllElements();
        for (int i = 0; i < lista.size(); i++) {
            modelo.addElement(lista.get(i));
        }
        comboCursos.setModel(modelo);
    }

    private void cargarListaGrados() {
        DefaultComboBoxModel modelo = (DefaultComboBoxModel) comboGrados.getModel();
        modelo.removeAllElements();
        modelo.addElement("Seleccione");
        modelo.addElement("0.  Transicion");
        modelo.addElement("1.  Primero");
        modelo.addElement("2.  Segundo");
        modelo.addElement("3.  Tercero");
        modelo.addElement("4.  Cuarto");
        modelo.addElement("5.  Quinto");
        modelo.addElement("6.  Sexto");
        modelo.addElement("7.  Séptimo");
        modelo.addElement("8.  Octavo");
        modelo.addElement("9.  Noveno");
        modelo.addElement("10.  Decimo");
        modelo.addElement("11.  Once");

    }

    private void cargarPeriodo() {
        SpinnerNumberModel modelo = (SpinnerNumberModel) periodoSpin.getModel();
        modelo.setMaximum(4);
        modelo.setMinimum(0);
        periodoSpin.setModel(modelo);
    }

    private void cargarListaLogros(Integer idAsignatura) {
        DefaultTableModel modelo = (DefaultTableModel) tablaLogros.getModel();
        List lista;

        int a = modelo.getRowCount();
        for (int i = 0; i < a; i++) {
            modelo.removeRow(0);
        }
        Object[] fila = new Object[4];
        Object[] dato = new Object[3];
        lista = logroBo.consultarListaLogros(idAsignatura, Integer.parseInt(periodoSpin.getValue() + ""));
        for (int i = 0; i < lista.size(); i++) {
            dato = (Object[]) lista.get(i);
            fila[1] = dato[0];
            fila[2] = dato[1];
            fila[3] = dato[2];
            fila[0] = i + 1;
            modelo.addRow(fila);
        }
        tablaLogros.setModel(modelo);

    }

    private void cargarListaLogros(Integer idAsignatura, int periodo) {
        DefaultTableModel modelo = (DefaultTableModel) tablaLogros.getModel();
        List lista;

        int a = modelo.getRowCount();
        for (int i = 0; i < a; i++) {
            modelo.removeRow(0);
        }
        Object[] fila = new Object[4];
        Object[] dato = new Object[3];
        lista = logroBo.consultarListaLogros(idAsignatura, periodo);
        for (int i = 0; i < lista.size(); i++) {
            dato = (Object[]) lista.get(i);
            fila[1] = dato[0];
            fila[2] = dato[1];
            fila[3] = dato[2];
            fila[0] = i + 1;
            modelo.addRow(fila);
        }
        tablaLogros.setModel(modelo);

    }

    private void comboGradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboGradosActionPerformed
        cargarListaAsignaturas();
        cargarListaCursosGrado(comboGrados.getSelectedIndex() - 1);
    }//GEN-LAST:event_comboGradosActionPerformed

    private void comboAreasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboAreasActionPerformed
        cargarListaAsignaturas();
    }//GEN-LAST:event_comboAreasActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        List<Estudiante> estudiantes = estudianteBo.encontrarEstudiantesAsignadosAGrado((comboGrados.getSelectedIndex() - 1) + "");
        int a = tablaLogros.getRowCount();
        int b = 0;
        int idLogro = 0;
        for (int i = 0; i < a; i++) {
            if (tablaLogros.getValueAt(i, 2).equals(entradaLogro.getText())) {
                b = 1;
                i = a + 1;
            }
        }

        if ((comboAsignaturas.getSelectedItem() + "").equals("") || entradaLogro.getText().equals("") || Integer.parseInt(periodoSpin.getValue().toString()) == 0) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar una asignatura, digitar un logro y seleccionar un periodo para registrarlo", "Registro fallido", JOptionPane.ERROR_MESSAGE);
        }
        else if(b == 1) {
            JOptionPane.showMessageDialog(this, "Logros con la misma descripcion", "Registro fallido", JOptionPane.ERROR_MESSAGE);

        }
        else if((comboCursos.getSelectedItem() + "").equals("")) {
            JOptionPane.showMessageDialog(this, "Seleccione un curso porfavor", "Registro fallido", JOptionPane.ERROR_MESSAGE);
        }
        else {
            idLogro = logroBo.crearLogro(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), Integer.parseInt(periodoSpin.getValue().toString()), entradaLogro.getText());
            cargarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""));
            entradaLogro.setText("");
            estudianteLogroBo.crearEstudianteLogro(estudiantes, idLogro, null);
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void comboAsignaturasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboAsignaturasActionPerformed
        entradaLogro.setText("");
        cargarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""));

    }//GEN-LAST:event_comboAsignaturasActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        int a = tablaLogros.getSelectedRow();
        logroBo.borrarLogro(Integer.parseInt(tablaLogros.getValueAt(a, 1) + ""));
        cargarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""));
    }//GEN-LAST:event_jButton5ActionPerformed

    private void comboPeriodoConsultaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboPeriodoConsultaActionPerformed
        cargarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodoConsulta.getSelectedIndex());
    }//GEN-LAST:event_comboPeriodoConsultaActionPerformed

    private void comboPeriodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboPeriodoActionPerformed
        inicializarTablaCalificaciones();
    }//GEN-LAST:event_comboPeriodoActionPerformed

    private void inicializarTablaCalificaciones() {
        List<Estudiante> listaEstudiantes = estudianteBo.encontrarEstudiantesAsignadosACurso(comboCursos.getSelectedItem() + "");
        int numfilas = listaEstudiantes.size();
        List listaLogros = logroBo.consultarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodo.getSelectedIndex());
        int numcolumnas = listaLogros.size();
        List<EstudianteLogro> listaEstLog = estudianteLogroBo.consultarListaEstLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""));
        String nombreColumna[] = new String[numcolumnas + 2];
        for (int i = 0; i < numcolumnas + 2; i++) {
            if (i == 0) {
                nombreColumna[i] = "Doc. Identidad";
            }
            else if (i == 1) {
                nombreColumna[i] = "Nombre del Estudiante";
            }
            else {
                nombreColumna[i] = "L" + (i - 1);
            }
        }

        tablaCalificaciones.setModel((TableModel) new DefaultTableModelImpl(
                new Object[numfilas][numcolumnas + 2],
                nombreColumna));
        Object[] dato = new Object[3];

        for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {
            this.tablaCalificaciones.setValueAt(listaEstudiantes.get(indicefilas).getDocEstudiante(), indicefilas, 0);
            this.tablaCalificaciones.setValueAt(listaEstudiantes.get(indicefilas).getNombreEst() + " " + listaEstudiantes.get(indicefilas).getApellidoEst(), indicefilas, 1);

            for (int indicelogros = 2; indicelogros < numcolumnas + 2; indicelogros++) {
                dato = (Object[]) listaLogros.get(indicelogros - 2);
                this.tablaCalificaciones.setValueAt(estudianteLogroBo.encontrarCalificacionLogroEst(listaEstudiantes.get(indicefilas).getIdEstudiante() + "", dato[0] + ""), indicefilas, indicelogros);
            }
        }
    }

    private void comboCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCursosActionPerformed
        inicializarTablaCalificaciones();
    }//GEN-LAST:event_comboCursosActionPerformed

    private void botonRegistrarCalificacionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonRegistrarCalificacionesActionPerformed
//Actualizar los datos de la tabla tablaCalificaciones en la BD
        boolean cal;
        List<Estudiante> listaEstudiantes = estudianteBo.encontrarEstudiantesAsignadosACurso(comboCursos.getSelectedItem() + "");
        int numfilas = listaEstudiantes.size();
        List listaLogros = logroBo.consultarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodo.getSelectedIndex());
        int numcolumnas = listaLogros.size();
        Object[] dato = new Object[3];
         for (int indicefilas = 0; indicefilas < numfilas; indicefilas++) {

            for (int indicelogros = 2; indicelogros < numcolumnas + 2; indicelogros++) {
                dato = (Object[]) listaLogros.get(indicelogros - 2);
                estudianteLogroBo.actualizarCalificaciones(listaEstudiantes.get(indicefilas).getIdEstudiante()+"",dato[0]+"",this.tablaCalificaciones.getValueAt(indicefilas, indicelogros).toString());

            }
        }




    }//GEN-LAST:event_botonRegistrarCalificacionesActionPerformed

    private void actualizarDescripciónActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actualizarDescripciónActionPerformed
        int x = tablaLogros.getRowCount();
        int validar = 0;

        for (int i = 0; i < x; i++) {
            String nuevaDescripcion = (String) tablaLogros.getValueAt(i, 2);
            int idLogro = (Integer) tablaLogros.getValueAt(i, 1);
            validar = logroBo.actualizarLogro(idLogro, nuevaDescripcion);
            if (validar == 0) {
                System.out.println("ErrorBD");
            }

        }
        cargarListaLogros(asignaturaBo.encontrarAsignatura(comboAsignaturas.getSelectedItem() + ""), comboPeriodoConsulta.getSelectedIndex());
    }//GEN-LAST:event_actualizarDescripciónActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazRegistrarCalificaciones().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton actualizarDescripción;
    private javax.swing.JButton botonRegistrarCalificaciones;
    private javax.swing.JComboBox comboAreas;
    private javax.swing.JComboBox comboAsignaturas;
    private javax.swing.JComboBox comboCursos;
    private javax.swing.JComboBox comboGrados;
    private javax.swing.JComboBox comboPeriodo;
    private javax.swing.JComboBox comboPeriodoConsulta;
    private javax.swing.JTextField entradaLogro;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner periodoSpin;
    private javax.swing.JTable tablaCalificaciones;
    private javax.swing.JTable tablaLogros;
    // End of variables declaration//GEN-END:variables
}
